import Vue from "vue";

import Cookies from "js-cookie";

import Element from "element-ui";
import "./assets/styles/element-variables.scss";

import "@/assets/styles/index.scss"; // global css
import "@/assets/styles/eam.scss";
import "@/utils/device";
import App from "./App";
import store from "./store";
import router from "./router";
import permission from "./directive/permission";
import "./utils/request.js";

import Tinymce from "@/utils/tinymce/index.vue";

Vue.component("tinymce", Tinymce);

import "./assets/icons"; // icon
import "./permission"; // permission control

import { getConfigKey } from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictName,
  selectDictLabels,
  download,
  handleTree,
  deepCopyData,
  dictToMap,
  mergeData,
  getOwnFirstLine,
  getTreeData,
  treeToArr,
  toTeamTimeSep,
  toFix,
} from "@/utils/eam";
import Pagination from "@/components/Pagination";
// 自定义表格工具扩展
import RightToolbar from "@/components/RightToolbar";
// 代码高亮插件
import hljs from "highlight.js";
import "highlight.js/styles/github-gist.css";

//重写组件
import "@/rewrite/index.js";

import mixins from '@/mixins';
Vue.mixin(mixins)

import echarts from "echarts"; //引入echarts
Vue.prototype.$echarts = echarts; //引入组件


//自定义全局指令，input聚焦
Vue.directive("focus", {
  // inserted: function (el, obj) {  //这是需要页面刚加载就能进行聚焦操作使用的钩子函数,可以省略的，视具体需求而定
  //   // console.log(obj);
  //   if (obj.value) { //对值进行判断
  //     // 聚焦元素
  //     el.querySelector('input').focus()
  //   }
  // },
  // 当指令所在组件的 VNode 及其子 VNode 全部更新后调用
  componentUpdated: function (el, obj) {
    //这是每当绑定的值发生改变时触发的钩子函数
    // console.log(obj.value);  //可以打印看一下
    if (obj.value) {
      el.querySelector("input").focus();
    }
  },
});

//引入自定义公共方法
import utils from "@/utils/util";
Vue.prototype.utils = utils;

// 全局方法挂载
Vue.prototype.getConfigKey = getConfigKey;
Vue.prototype.parseTime = parseTime;
Vue.prototype.resetForm = resetForm;
Vue.prototype.addDateRange = addDateRange;
Vue.prototype.selectDictLabel = selectDictLabel;
Vue.prototype.selectDictName = selectDictName;
Vue.prototype.selectDictLabels = selectDictLabels;
Vue.prototype.download = download;
Vue.prototype.handleTree = handleTree;
Vue.prototype.deepCopyData = deepCopyData;
Vue.prototype.dictToMap = dictToMap;
Vue.prototype.mergeData = mergeData;
Vue.prototype.getOwnFirstLine = getOwnFirstLine;
Vue.prototype.getTreeData = getTreeData;
Vue.prototype.treeToArr = treeToArr;
Vue.prototype.toFix = toFix;
Vue.prototype.toTeamTimeSep = toTeamTimeSep
Vue.prototype.msgSuccess = function (msg) {
  this.$message({ showClose: true, message: msg, type: "success" });
};

Vue.prototype.msgError = function (msg) {
  this.$message({ showClose: true, message: msg, type: "error" });
};

Vue.prototype.msgWarning = function (msg) {
  this.$message({ message: msg, type: "warning" });
};

Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
};

//保留几位小数
import inputLimt from "@/directive/inputLimt";
Vue.use(inputLimt);
//element弹框拖拽
import dialogDrag from "@/directive/dialogDrag";
Vue.use(dialogDrag);
// v-dialogDragWidth: 弹窗宽度拖大 拖小
import dialogDragWidth from "@/directive/dialogDragWidth";
Vue.use(dialogDragWidth);
// v-elementDrag: 元素拖拽
import elementDrag from "@/directive/elementDrag";
Vue.use(elementDrag);

// 全局组件挂载
Vue.component("Pagination", Pagination);
Vue.component("RightToolbar", RightToolbar);

Vue.use(permission);
Vue.use(hljs.vuePlugin);

//分区标题
import PartitionTitle from "@/components/PartitionTitle";
Vue.component("PartitionTitle", PartitionTitle);

//导入
import FileImport from "@/components/FileImport";
Vue.component("FileImport", FileImport);

//图片上传
import ImgUpload from "@/components/ImgUpload";
Vue.component("ImgUpload", ImgUpload);

//附件上传
import uploadImage from "@/components/CustomUploadImg";
Vue.component("uploadImage", uploadImage);

// 左右拉伸组件
import SideBar from "@/components/SideBar";
Vue.component("SideBar", SideBar);

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
Vue.component("treeselect", Treeselect);

//菜单
import moduleTree from "@/views/components/moduleTree";
Vue.component("moduleTree", moduleTree);
//组织机构
import organization from "@/views/components/organization";
Vue.component("organization", organization);

//组织机构弹框
import organizationDialog from "@/views/components/organizationDialog";
Vue.component("organizationDialog", organizationDialog);

//用户列表
import userList from "@/views/components/userList";
Vue.component("userList", userList);

//角色弹框
import roles from "@/views/components/roles";
Vue.component("roles", roles);

//多选用户列表
import userList2 from "@/views/components/userList2";
Vue.component("userList2", userList2);

//模板展示组件
import Parser from "@/utils/parser/Parser";
Vue.component("Parser", Parser);

//文字滚动
import StringCarousel from "@/components/StringCarousel";
Vue.component("StringCarousel", StringCarousel);

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get("size") || "medium", // set element-ui default size
});

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: (h) => h(App),
});
